﻿using System;
using System.IO;
using System.Net;
using System.Text;
using UnityEditor;
using UnityEngine;
namespace QQSDK
{
    public class SDKEditor : EditorWindow
    {
        const string OM_APP_Key_lable = "OpenMediation App Key";
        const string OM_Banner_ID_lable = "OpenMediation Banner id";
        const string OM_Splash_ID_lable = "OpenMediation Splash id";

        const string Enable_Splash_floating = "Enable_Splash_floating";

        const string Adjust_app_token_lable = "Adjust_app_token";
        const string Adjust_default_track_token_lable = "Default Tracker Name";
        const string Adjust_secrets_lable = "Adjsut Secrets";
        const string Adjust_Splsah_Impression_token_lable = "Splash Impression token";
        const string Adjust_Banner_Impression_token_lable = "Banner Impression token";
        const string Adjust_Interstitial_Impression_token_lable = "Interstitial Impression token";
        const string Adjust_Reward_Impression_token_lable = "Reward Impression token";

        const string Facebook_App_id__lable = "Facebook App id";
        const string Admob_App_id__lable = "Admob App id";
        const string Reyun_App_id__lable = "ReYun App id";

        const string FirebaseCrashAnalytics_lable = "FirebaseCrashAnalytics";

        const string BuglyCrash_lable = "BuglyCrashAnalytics";

        static float _spacing = 2;
        //文件存储路径
        private string configFilePath;
        //平台商店
        private enum PlatformStore
        {
            Google,
            iOS,
            China,
            Unknow
        }
        //当前选择的商店平台
        private PlatformStore selectedPlatformStore = PlatformStore.Unknow;
        private enum MediationType
        {
            OpemMedition,
            Unknow
        }
        //当前选择的聚合类型
        // private MediationType selectedMediationType = MediationType.Unknow;
        //中国商店类型
        private enum ChinaStoreType
        {
            ByteDance,
            Unknow
        }
        //当前选择的中国商店类型
        private ChinaStoreType selectedChinaStoreType = ChinaStoreType.Unknow;
        /// <summary>
        /// 编辑器初始化
        /// </summary>
        public SDKEditor()
        {
            this.titleContent = new GUIContent("Settings");
        }
        /// <summary>
        /// 打开编辑器面板
        /// </summary>
        [MenuItem("QQSDK/Set")]
        static void ShowWindwos()
        {
            GetWindow(typeof(SDKEditor));
        }


        [MenuItem("QQSDK/清除编辑器缓存")]
        private static void ClearAllRecordManual()
        {
            //清除所有的PlayerPrefs
            PlayerPrefs.DeleteAll();

            SDKFunc.LogError("==========清除所有PlayerPrefs记录");

            //目标文件夹
            string targetDirectory = Application.persistentDataPath;

            //如果目标文件夹存在
            if (Directory.Exists(targetDirectory))
            {
                //删除
                Directory.Delete(targetDirectory, true);
            }

            SDKFunc.LogError("==========清除持久化目录");

            //目标文件夹
            string targetDirectory1 = "C:\\Users\\" + Environment.UserName + "\\AppData\\LocalLow\\Unity\\" + PlayerSettings.companyName + "_" + PlayerSettings.productName + "";

            SDKFunc.LogError(targetDirectory1);

            //如果目标文件夹存在
            if (Directory.Exists(targetDirectory1))
            {
                //删除
                Directory.Delete(targetDirectory1, true);
                SDKFunc.LogError("==========清除AB包缓存目录");
            }
        }


        private SDKData data; //所有数据
        /// <summary>
        /// 数据初始化
        /// </summary>
        void OnEnable()
        {
            LoadData();
        }
        void OnGUI()
        {
            GUILayout.BeginVertical();
            selectedPlatformStore = (PlatformStore)GUILayout.Toolbar((int)selectedPlatformStore, new string[] { "Google", "iOS", "China Android" }, GUILayout.Height(30));
            SwitchMediationTypeSettingDashboard();
            GUILayout.EndVertical();
        }

        void SwitchMediationTypeSettingDashboard()
        {
            switch (selectedPlatformStore)
            {
                case PlatformStore.Google:
                    SetGooglePlatformStoreSettingBoard();
                    break;
                case PlatformStore.China:
                    SetChinaPlatformStoreSettingBoard();
                    break;
                case PlatformStore.iOS:
                    SetiOSPlatformStoreSettingBoard();
                    break;
            }
            //ltt mark
            //SettingFacebook();
            //SettingAdmob();

            //SettingAdjust();
            //SetThinkingData();
            //SetttingCrashAnalytics();
            //SettingReyun();
            //Generation();
        }

        void LoadData()
        {
            configFilePath = Application.dataPath + "/QQSDK/Ads/Res/" + "sdkConfig.json"; //读取文件路径
            data = JsonMapper.ToObject<SDKData>(File.ReadAllText(configFilePath));
            selectedPlatformStore = (PlatformStore)data.platformStore;

            google_Data = data.googleStore; //gp版本数据
            appleStore_Data = data.appleStore; //iOS版本数据
            china_Store_Data = data.chinaStore; //中国anroid版本数据

            ///google 版本相关数据
            google_OM_Data = data.googleStore.openMediationData;
            google_Adjust_Data = data.googleStore.adjustData;
            google_Thinking_Data = data.googleStore.thinkingData;
            google_Facebook_Data = data.googleStore.facebookData;
            google_Admob_Data = data.googleStore.admobData;
            google_crash_Analytics_Data = data.googleStore.crashAnalyticsData;
            //  = data.googleStore.firbeaseData;
            ///国内安卓版本详细数据
            chinaOM = data.chinaStore.openMediationData;
            china_Adjust_Data = data.chinaStore.adjustData;
            china_Thinking_Data = data.chinaStore.thinkingData;
            china_crashAnalytics_Data = data.chinaStore.crashAnalyticsData;
            china_Reyun_Data = data.chinaStore.reyunData;

            ///iOS相关数据
            apple_OM_Data = data.appleStore.openMediationData;
            apple_Adjust_Data = data.appleStore.adjustData;
            apple_Thinking_Data = data.appleStore.thinkingData;
            apple_Facebook_Data = data.appleStore.facebookData;
            apple_Admob_Data = data.appleStore.admobData;
            apple_Reyun_Data = data.appleStore.reyunData;
            apple_crash_analytics_Data = data.appleStore.crashAnalyticsData;
        }

        #region Adjust 
        /// <summary>
        /// 设置Adjust参数
        /// </summary>
        void SettingAdjust()
        {
            GUILayout.Space(_spacing);
            EditorGUILayout.BeginHorizontal();
            GUI.skin.label.fontSize = 10;
            GUI.skin.label.alignment = TextAnchor.MiddleCenter;
            GUILayout.Label("Adjust Setting");
            EditorGUILayout.EndHorizontal();
            switch (selectedPlatformStore)
            {
                case PlatformStore.Google:
                    google_Adjust_Data.app_token = EditorGUILayout.TextField(Adjust_app_token_lable, google_Adjust_Data.app_token, GUILayout.Width(400));
                    google_Adjust_Data.enable_default_trackName = GUILayout.Toggle(google_Adjust_Data.enable_default_trackName, Adjust_default_track_token_lable);
                    if (google_Adjust_Data.enable_default_trackName)
                    {
                        google_Adjust_Data.default_trackName_token = EditorGUILayout.TextField(Adjust_default_track_token_lable, google_Adjust_Data.default_trackName_token, GUILayout.Width(300));
                    }
                    google_Adjust_Data.enable_secrets = GUILayout.Toggle(google_Adjust_Data.enable_secrets, Adjust_secrets_lable);
                    if (google_Adjust_Data.enable_secrets)
                    {
                        google_Adjust_Data.secretID = EditorGUILayout.TextField(Adjust_secrets_lable, google_Adjust_Data.secretID, GUILayout.Width(300));
                        google_Adjust_Data.info1 = EditorGUILayout.TextField("Info1", google_Adjust_Data.info1, GUILayout.Width(300));
                        google_Adjust_Data.info2 = EditorGUILayout.TextField("Info2", google_Adjust_Data.info2, GUILayout.Width(300));
                        google_Adjust_Data.info3 = EditorGUILayout.TextField("Info3", google_Adjust_Data.info3, GUILayout.Width(300));
                        google_Adjust_Data.info4 = EditorGUILayout.TextField("Info4", google_Adjust_Data.info4, GUILayout.Width(300));
                    }
                    google_Adjust_Data.splash_im_token = EditorGUILayout.TextField(Adjust_Splsah_Impression_token_lable, google_Adjust_Data.splash_im_token, GUILayout.Width(400));
                    google_Adjust_Data.banner_im_token = EditorGUILayout.TextField(Adjust_Banner_Impression_token_lable, google_Adjust_Data.banner_im_token, GUILayout.Width(400));
                    google_Adjust_Data.interstitial_im_token = EditorGUILayout.TextField(Adjust_Interstitial_Impression_token_lable, google_Adjust_Data.interstitial_im_token, GUILayout.Width(400));
                    google_Adjust_Data.rewardvideo_im_token = EditorGUILayout.TextField(Adjust_Reward_Impression_token_lable, google_Adjust_Data.rewardvideo_im_token, GUILayout.Width(400));
                    break;
                case PlatformStore.iOS:
                    apple_Adjust_Data.app_token = EditorGUILayout.TextField(Adjust_app_token_lable, apple_Adjust_Data.app_token, GUILayout.Width(400));

                    apple_Adjust_Data.enable_secrets = GUILayout.Toggle(apple_Adjust_Data.enable_secrets, Adjust_secrets_lable);
                    if (apple_Adjust_Data.enable_secrets)
                    {
                        apple_Adjust_Data.secretID = EditorGUILayout.TextField("SecretID", apple_Adjust_Data.secretID, GUILayout.Width(300));
                        apple_Adjust_Data.info1 = EditorGUILayout.TextField("Info1", apple_Adjust_Data.info1, GUILayout.Width(300));
                        apple_Adjust_Data.info2 = EditorGUILayout.TextField("Info2", apple_Adjust_Data.info2, GUILayout.Width(300));
                        apple_Adjust_Data.info3 = EditorGUILayout.TextField("Info3", apple_Adjust_Data.info3, GUILayout.Width(300));
                        apple_Adjust_Data.info4 = EditorGUILayout.TextField("Info4", apple_Adjust_Data.info4, GUILayout.Width(300));
                    }
                    apple_Adjust_Data.splash_im_token = EditorGUILayout.TextField(Adjust_Splsah_Impression_token_lable, apple_Adjust_Data.splash_im_token, GUILayout.Width(400));
                    apple_Adjust_Data.banner_im_token = EditorGUILayout.TextField(Adjust_Banner_Impression_token_lable, apple_Adjust_Data.banner_im_token, GUILayout.Width(400));
                    apple_Adjust_Data.interstitial_im_token = EditorGUILayout.TextField(Adjust_Interstitial_Impression_token_lable, apple_Adjust_Data.interstitial_im_token, GUILayout.Width(400));
                    apple_Adjust_Data.rewardvideo_im_token = EditorGUILayout.TextField(Adjust_Reward_Impression_token_lable, apple_Adjust_Data.rewardvideo_im_token, GUILayout.Width(400));
                    break;
                case PlatformStore.China:
                    china_Adjust_Data.app_token = EditorGUILayout.TextField(Adjust_app_token_lable, china_Adjust_Data.app_token, GUILayout.Width(400));
                    china_Adjust_Data.enable_default_trackName = GUILayout.Toggle(china_Adjust_Data.enable_default_trackName, Adjust_default_track_token_lable);
                    if (china_Adjust_Data.enable_default_trackName)
                    {
                        china_Adjust_Data.default_trackName_token = EditorGUILayout.TextField(Adjust_default_track_token_lable, china_Adjust_Data.default_trackName_token, GUILayout.Width(300));
                    }
                    china_Adjust_Data.enable_secrets = GUILayout.Toggle(china_Adjust_Data.enable_secrets, Adjust_secrets_lable);
                    if (china_Adjust_Data.enable_secrets)
                    {
                        china_Adjust_Data.secretID = EditorGUILayout.TextField("SecretID", china_Adjust_Data.secretID, GUILayout.Width(300));
                        china_Adjust_Data.info1 = EditorGUILayout.TextField("Info1", china_Adjust_Data.info1, GUILayout.Width(300));
                        china_Adjust_Data.info2 = EditorGUILayout.TextField("Info2", china_Adjust_Data.info2, GUILayout.Width(300));
                        china_Adjust_Data.info3 = EditorGUILayout.TextField("Info3", china_Adjust_Data.info3, GUILayout.Width(300));
                        china_Adjust_Data.info4 = EditorGUILayout.TextField("Info4", china_Adjust_Data.info4, GUILayout.Width(300));
                    }
                    china_Adjust_Data.splash_im_token = EditorGUILayout.TextField(Adjust_Splsah_Impression_token_lable, china_Adjust_Data.splash_im_token, GUILayout.Width(400));
                    china_Adjust_Data.banner_im_token = EditorGUILayout.TextField(Adjust_Banner_Impression_token_lable, china_Adjust_Data.banner_im_token, GUILayout.Width(400));
                    china_Adjust_Data.interstitial_im_token = EditorGUILayout.TextField(Adjust_Interstitial_Impression_token_lable, china_Adjust_Data.interstitial_im_token, GUILayout.Width(400));
                    china_Adjust_Data.rewardvideo_im_token = EditorGUILayout.TextField(Adjust_Reward_Impression_token_lable, china_Adjust_Data.rewardvideo_im_token, GUILayout.Width(400));
                    break;
            }
        }
        #endregion

        #region Admob
        void SettingAdmob()
        {
            if (selectedPlatformStore == PlatformStore.China)
                return;
            GUILayout.Space(_spacing);
            EditorGUILayout.BeginHorizontal();
            GUI.skin.label.fontSize = 10;
            GUI.skin.label.alignment = TextAnchor.MiddleCenter;
            GUILayout.Label("Admob Setting");
            EditorGUILayout.EndHorizontal();
            if (selectedPlatformStore == PlatformStore.Google)
            {
                google_Admob_Data.app_id = EditorGUILayout.TextField("Admob_app_id", google_Admob_Data.app_id);
            }
            else if (selectedPlatformStore == PlatformStore.iOS)
            {
                apple_Admob_Data.app_id = EditorGUILayout.TextField("Admob_app_id", apple_Admob_Data.app_id);
            }
            GUILayout.Space(10);
        }
        #endregion

        void SetttingCrashAnalytics()
        {
            GUILayout.Space(_spacing);
            EditorGUILayout.BeginHorizontal();
            GUI.skin.label.fontSize = 10;
            GUI.skin.label.alignment = TextAnchor.MiddleCenter;
            GUILayout.Label("Crash Analytics Setting");
            EditorGUILayout.EndHorizontal();
            if (selectedPlatformStore == PlatformStore.Google)
            {
                google_crash_Analytics_Data.enable = GUILayout.Toggle(google_crash_Analytics_Data.enable, FirebaseCrashAnalytics_lable);
            }
            else if (selectedPlatformStore == PlatformStore.iOS)
            {
                apple_crash_analytics_Data.enable = GUILayout.Toggle(apple_crash_analytics_Data.enable, FirebaseCrashAnalytics_lable);
            }

            else if (selectedPlatformStore == PlatformStore.China)
            {
                china_crashAnalytics_Data.enable = GUILayout.Toggle(china_crashAnalytics_Data.enable, BuglyCrash_lable);
                if (china_crashAnalytics_Data.enable)
                {
                    china_crashAnalytics_Data.bugly_app_id = EditorGUILayout.TextField("Bugly_app_id", china_crashAnalytics_Data.bugly_app_id);
                }
            }
        }
        #region Facebook
        void SettingFacebook()
        {
            if (selectedPlatformStore == PlatformStore.China)
                return;
            GUILayout.Space(_spacing);
            EditorGUILayout.BeginHorizontal();
            GUI.skin.label.fontSize = 10;
            GUI.skin.label.alignment = TextAnchor.MiddleCenter;
            GUILayout.Label("Facebook Setting");
            EditorGUILayout.EndHorizontal();
            if (selectedPlatformStore == PlatformStore.Google)
            {
                google_Facebook_Data.app_id = EditorGUILayout.TextField(Facebook_App_id__lable, google_Facebook_Data.app_id);
            }
            else if (selectedPlatformStore == PlatformStore.iOS)
            {
                apple_Facebook_Data.app_id = EditorGUILayout.TextField(Facebook_App_id__lable, apple_Facebook_Data.app_id);
            }
            GUILayout.Space(10);
        }
        #endregion

        #region Reyun
        void SettingReyun()
        {
            if (selectedPlatformStore == PlatformStore.Google)
                return;
            GUILayout.Space(_spacing);
            EditorGUILayout.BeginHorizontal();
            GUI.skin.label.fontSize = 10;
            GUI.skin.label.alignment = TextAnchor.MiddleCenter;
            GUILayout.Label("Reyun Setting");
            EditorGUILayout.EndHorizontal();
            if (selectedPlatformStore == PlatformStore.China)
            {
                // google_Facebook_Data.app_id = EditorGUILayout.TextField(Reyun_App_id__lable, google_Facebook_Data.app_id);
                china_Reyun_Data.app_id = EditorGUILayout.TextField("ReYun App key", china_Reyun_Data.app_id);
            }
            else if (selectedPlatformStore == PlatformStore.iOS)
            {
                apple_Reyun_Data.app_id = EditorGUILayout.TextField("ReYun App key", apple_Reyun_Data.app_id);
            }
            GUILayout.Space(10);
        }
        #endregion

        #region ThinkingData
        void SetThinkingData()
        {
            GUILayout.Space(_spacing);
            EditorGUILayout.BeginHorizontal();
            GUI.skin.label.fontSize = 10;
            GUI.skin.label.alignment = TextAnchor.MiddleCenter;
            GUILayout.Label("ThinkingData Setting");
            EditorGUILayout.EndHorizontal();
            switch (selectedPlatformStore)
            {
                case PlatformStore.Google:
                    google_Thinking_Data.url = EditorGUILayout.TextField("Url", google_Thinking_Data.url);
                    google_Thinking_Data.app_id = EditorGUILayout.TextField("App_id", google_Thinking_Data.app_id);
                    break;
                case PlatformStore.iOS:
                    apple_Thinking_Data.url = EditorGUILayout.TextField("Url", apple_Thinking_Data.url);
                    apple_Thinking_Data.app_id = EditorGUILayout.TextField("App_id", apple_Thinking_Data.app_id);
                    break;
                case PlatformStore.China:
                    china_Thinking_Data.url = EditorGUILayout.TextField("Url", china_Thinking_Data.url);
                    china_Thinking_Data.app_id = EditorGUILayout.TextField("App_id", china_Thinking_Data.app_id);
                    break;
            }
        }
        #endregion

        private SDKData.AppleStore appleStore_Data;
        private SDKData.OpenMediationData apple_OM_Data;
        private SDKData.AdjustData apple_Adjust_Data;
        private SDKData.ThinkingData apple_Thinking_Data;
        private SDKData.FacebookData apple_Facebook_Data;
        private SDKData.AdmobData apple_Admob_Data;
        private SDKData.ReyunData apple_Reyun_Data;
        private SDKData.CrashAnalyticsData apple_crash_analytics_Data;

        #region iOS
        void SetiOSPlatformStoreSettingBoard()
        {
            appleStore_Data = data.appleStore;
            EditorGUILayout.BeginVertical();
            apple_OM_Data.app_id = EditorGUILayout.TextField(OM_APP_Key_lable, apple_OM_Data.app_id);
            apple_OM_Data.banner_id = EditorGUILayout.TextField(OM_Banner_ID_lable, apple_OM_Data.banner_id);
            apple_OM_Data.splash_id = EditorGUILayout.TextField(OM_Splash_ID_lable, apple_OM_Data.splash_id);

            EditorGUILayout.EndVertical();
        }

        #endregion

        SDKData.GoogleStore google_Data; //读取到的谷歌版数据
        SDKData.OpenMediationData google_OM_Data; //读取到的谷歌版max聚合数据
        SDKData.AdjustData google_Adjust_Data; //读取到的Adjust数据
        SDKData.AdmobData google_Admob_Data; //admob id
        SDKData.ThinkingData google_Thinking_Data; //读取到的数数数据
        SDKData.FacebookData google_Facebook_Data; //facebook id
        private SDKData.CrashAnalyticsData google_crash_Analytics_Data; //Crash数据

        #region Google Store
        void SetGooglePlatformStoreSettingBoard()
        {
            google_Data = data.googleStore;
            EditorGUILayout.BeginVertical();
            google_OM_Data.app_id = EditorGUILayout.TextField(OM_APP_Key_lable, google_OM_Data.app_id);
            google_OM_Data.banner_id = EditorGUILayout.TextField(OM_Banner_ID_lable, google_OM_Data.banner_id);

            EditorGUILayout.EndVertical();
        }
        #endregion

        #region ChinaAnadroid
        SDKData.ChinaStore china_Store_Data; //读取到的谷歌版数据
        SDKData.OpenMediationData chinaOM; //读取到的谷歌版Mopub聚合数据
        SDKData.AdjustData china_Adjust_Data; //读取到的Adjust数据
        SDKData.ReyunData china_Reyun_Data; //读取到的Adjust数据
        SDKData.ThinkingData china_Thinking_Data; //读取到的数数数据
        SDKData.CrashAnalyticsData china_crashAnalytics_Data; //读取到的数数数据

        void SetChinaPlatformStoreSettingBoard()
        {
            china_Store_Data = data.chinaStore;
            chinaOM = china_Store_Data.openMediationData;
            chinaOM.app_id = EditorGUILayout.TextField(OM_APP_Key_lable, chinaOM.app_id);
            chinaOM.banner_id = EditorGUILayout.TextField(OM_Banner_ID_lable, chinaOM.banner_id);
        }
        #endregion

        #region 生成数据
        /// <summary>
        /// 准备生成配置文件
        /// </summary>
        void Generation()
        {
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Set up", GUILayout.Height(50)))
            {
                SDKData sdkJsonData;
                SDKData.GoogleStore googleStoreJsonData = null;
                SDKData.AppleStore appleStoreJsonData = null;
                SDKData.ChinaStore chinaStoreJsonData = null;
                switch (selectedPlatformStore)
                {
                    //iOS 商店版本
                    case PlatformStore.iOS:
                        SDKData.OpenMediationData appleOMJsonData = null;
                        SDKData.AdjustData appleAdjustJsonData = new SDKData.AdjustData //全局的adjust 配置信息
                        {
                            app_token = apple_Adjust_Data.app_token,
                            enable_secrets = apple_Adjust_Data.enable_secrets,
                            secretID = apple_Adjust_Data.secretID,
                            info1 = apple_Adjust_Data.info1,
                            info2 = apple_Adjust_Data.info2,
                            info3 = apple_Adjust_Data.info3,
                            info4 = apple_Adjust_Data.info4,
                            splash_im_token = apple_Adjust_Data.splash_im_token,
                            banner_im_token = apple_Adjust_Data.banner_im_token,
                            interstitial_im_token = apple_Adjust_Data.interstitial_im_token,
                            rewardvideo_im_token = apple_Adjust_Data.rewardvideo_im_token
                        };
                        SDKData.ThinkingData appleThinkingDataJsonData = new SDKData.ThinkingData
                        {
                            app_id = apple_Thinking_Data.app_id,
                            url = apple_Thinking_Data.url,
                        };
                        SDKData.FacebookData appleFacebookData = new SDKData.FacebookData
                        {
                            app_id = apple_Facebook_Data.app_id,
                        };
                        SDKData.ReyunData appleReyunData = new SDKData.ReyunData
                        {
                            app_id = apple_Reyun_Data.app_id,
                        };
                        SDKData.AdmobData appleAdmobData = new SDKData.AdmobData
                        {
                            app_id = apple_Admob_Data.app_id,
                        };
                        SDKData.CrashAnalyticsData appleFirbeaseDataJson = new SDKData.CrashAnalyticsData
                        {
                            enable = apple_crash_analytics_Data.enable,
                        };
                        appleOMJsonData = new SDKData.OpenMediationData();
                        appleOMJsonData.app_id = apple_OM_Data.app_id;
                        appleOMJsonData.banner_id = apple_OM_Data.banner_id;
                        appleOMJsonData.splash_id = apple_OM_Data.splash_id;

                        appleStoreJsonData = new SDKData.AppleStore
                        {
                            openMediationData = appleOMJsonData,
                            facebookData = appleFacebookData,
                            admobData = appleAdmobData,
                            adjustData = appleAdjustJsonData,
                            thinkingData = appleThinkingDataJsonData,
                            reyunData = appleReyunData,
                            crashAnalyticsData = apple_crash_analytics_Data,
                        };
                        googleStoreJsonData = google_Data;
                        chinaStoreJsonData = china_Store_Data;
                        break;

                    case PlatformStore.Google:
                        SDKData.OpenMediationData googleOMJsonData = null;
                        SDKData.AdjustData google_AdjustJsonData = new SDKData.AdjustData //全局的adjust 配置信息
                        {
                            app_token = google_Adjust_Data.app_token,
                            enable_default_trackName = google_Adjust_Data.enable_default_trackName,
                            default_trackName_token = google_Adjust_Data.default_trackName_token,
                            enable_secrets = google_Adjust_Data.enable_secrets,
                            secretID = google_Adjust_Data.secretID,
                            info1 = google_Adjust_Data.info1,
                            info2 = google_Adjust_Data.info2,
                            info3 = google_Adjust_Data.info3,
                            info4 = google_Adjust_Data.info4,
                            splash_im_token = apple_Adjust_Data.splash_im_token,
                            banner_im_token = google_Adjust_Data.banner_im_token,
                            interstitial_im_token = google_Adjust_Data.interstitial_im_token,
                            rewardvideo_im_token = google_Adjust_Data.rewardvideo_im_token
                        };
                        SDKData.ThinkingData google_ThinkingDataJsonData = new SDKData.ThinkingData
                        {
                            app_id = google_Thinking_Data.app_id,
                            url = google_Thinking_Data.url,
                        };
                        SDKData.FacebookData google_FacebookData = new SDKData.FacebookData
                        {
                            app_id = google_Facebook_Data.app_id,
                        };
                        SDKData.AdmobData google_AdmobData = new SDKData.AdmobData
                        {
                            app_id = google_Admob_Data.app_id,
                        };
                        SDKData.CrashAnalyticsData google_firbeaseDataJson = new SDKData.CrashAnalyticsData
                        {
                            enable = google_crash_Analytics_Data.enable,
                        };

                        googleOMJsonData = new SDKData.OpenMediationData();
                        googleOMJsonData.app_id = google_OM_Data.app_id;
                        googleOMJsonData.banner_id = google_OM_Data.banner_id;

                        googleStoreJsonData = new SDKData.GoogleStore
                        {
                            openMediationData = google_OM_Data,
                            facebookData = google_FacebookData,
                            admobData = google_AdmobData,
                            adjustData = google_AdjustJsonData,
                            thinkingData = google_ThinkingDataJsonData,
                            crashAnalyticsData = google_firbeaseDataJson,
                        };
                        appleStoreJsonData = appleStore_Data;
                        chinaStoreJsonData = china_Store_Data;
                        break;
                    case PlatformStore.China:
                        SDKData.OpenMediationData chinaOMJsonData = null;
                        SDKData.AdjustData chinaAdjustJsonData = new SDKData.AdjustData //全局的adjust 配置信息
                        {
                            app_token = china_Adjust_Data.app_token,
                            enable_default_trackName = china_Adjust_Data.enable_default_trackName,
                            enable_secrets = china_Adjust_Data.enable_secrets,
                            secretID = china_Adjust_Data.secretID,
                            info1 = china_Adjust_Data.info1,
                            info2 = china_Adjust_Data.info2,
                            info3 = china_Adjust_Data.info3,
                            info4 = china_Adjust_Data.info4,
                            splash_im_token = apple_Adjust_Data.splash_im_token,
                            banner_im_token = china_Adjust_Data.banner_im_token,
                            interstitial_im_token = china_Adjust_Data.interstitial_im_token,
                            rewardvideo_im_token = china_Adjust_Data.rewardvideo_im_token
                        };
                        SDKData.ThinkingData chinaThinkingDataJsonData = new SDKData.ThinkingData
                        {
                            app_id = china_Thinking_Data.app_id,
                            url = china_Thinking_Data.url,
                        };
                        SDKData.ReyunData chinaReyunData = new SDKData.ReyunData
                        {
                            app_id = china_Reyun_Data.app_id,
                        };
                        chinaOMJsonData = new SDKData.OpenMediationData();
                        SDKData.CrashAnalyticsData buglyCrashData = new SDKData.CrashAnalyticsData();
                        chinaOMJsonData.app_id = chinaOM.app_id;
                        chinaOMJsonData.splash_id = chinaOM.splash_id;
                        chinaOMJsonData.banner_id = chinaOM.banner_id;
                        buglyCrashData.bugly_app_id = china_crashAnalytics_Data.bugly_app_id;
                        buglyCrashData.enable = china_crashAnalytics_Data.enable;
                        chinaStoreJsonData = new SDKData.ChinaStore
                        {
                            openMediationData = chinaOMJsonData,
                            adjustData = chinaAdjustJsonData,
                            thinkingData = chinaThinkingDataJsonData,
                            crashAnalyticsData = buglyCrashData,
                            reyunData = chinaReyunData
                        };
                        googleStoreJsonData = google_Data;
                        appleStoreJsonData = appleStore_Data;
                        break;
                }
                sdkJsonData = new SDKData()
                {
                    platformStore = (int)selectedPlatformStore,
                    googleStore = googleStoreJsonData,
                    appleStore = appleStoreJsonData,
                    chinaStore = chinaStoreJsonData
                };
                SaveJsonFile(sdkJsonData);
            }
            GUILayout.EndHorizontal();
        }
        #endregion

        #region Save Data
        /// <summary>
        /// 保存编辑的所有参数
        /// </summary>
        /// <param name="jsonData"></param>
        void SaveJsonFile(SDKData jsonData)
        {
            string json = JsonMapper.ToJson(jsonData);
            string mediationName = string.Empty;
            if (selectedPlatformStore == PlatformStore.China)
            {
                mediationName = "头条";
            }
            bool isSwitch = EditorUtility.DisplayDialog("提示", "确认切换广告到" + selectedPlatformStore + "版本", "确认", "取消");
            if (isSwitch)
            {
                configFilePath = Application.dataPath + "/QQSDK/Ads/Res/" + "sdkConfig.json"; //配置文件保存路径
                File.WriteAllText(configFilePath, json);
                ShowNotification(new GUIContent("保存成功"));
                KKFileUtils.SetConfig(jsonData);
            }
            else
            {
                ShowNotification(new GUIContent("取消"));
            }
        }
        #endregion
    }
}